home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / netBoot / h / fsdir.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-13  |  3.0 KB  |  91 lines

  1. /*    @(#)fsdir.h 1.1 86/09/27 SMI; from UCB 4.5 82/11/13    */
  2.  
  3.  
  4. /*
  5.  * A directory consists of some number of blocks of DIRBLKSIZ
  6.  * bytes, where DIRBLKSIZ is chosen such that it can be transferred
  7.  * to disk in a single atomic operation (e.g. 512 bytes on most machines).
  8.  *
  9.  * Each DIRBLKSIZ byte block contains some number of directory entry
  10.  * structures, which are of variable length.  Each directory entry has
  11.  * a struct direct at the front of it, containing its inode number,
  12.  * the length of the entry, and the length of the name contained in
  13.  * the entry.  These are followed by the name padded to a 4 byte boundary
  14.  * with null bytes.  All names are guaranteed null terminated.
  15.  * The maximum length of a name in a directory is MAXNAMLEN.
  16.  *
  17.  * The macro DIRSIZ(dp) gives the amount of space required to represent
  18.  * a directory entry.  Free space in a directory is represented by
  19.  * entries which have dp->d_reclen > DIRSIZ(dp).  All DIRBLKSIZ bytes
  20.  * in a directory block are claimed by the directory entries.  This
  21.  * usually results in the last entry in a directory having a large
  22.  * dp->d_reclen.  When entries are deleted from a directory, the
  23.  * space is returned to the previous entry in the same directory
  24.  * block by increasing its dp->d_reclen.  If the first entry of
  25.  * a directory block is free, then its dp->d_ino is set to 0.
  26.  * Entries other than the first in a directory do not normally have
  27.  * dp->d_ino set to 0.
  28.  */
  29. /* so user programs can just include dir.h */
  30. #if !defined(KERNEL) && !defined(DEV_BSIZE)
  31. #define    DEV_BSIZE    512
  32. #endif
  33. #define DIRBLKSIZ    DEV_BSIZE
  34. #define    MAXNAMLEN    255
  35.  
  36. struct    direct {
  37.     u_long    d_ino;            /* inode number of entry */
  38.     u_short    d_reclen;        /* length of this record */
  39.     u_short    d_namlen;        /* length of string in d_name */
  40.     char    d_name[MAXNAMLEN + 1];    /* name must be no longer than this */
  41. };
  42.  
  43. /*
  44.  * The DIRSIZ macro gives the minimum record length which will hold
  45.  * the directory entry.  This requires the amount of space in struct direct
  46.  * without the d_name field, plus enough space for the name with a terminating
  47.  * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
  48.  */
  49. #undef DIRSIZ
  50. #define DIRSIZ(dp) \
  51.     ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
  52.  
  53. #ifndef KERNEL
  54. /*
  55.  * Definitions for library routines operating on directories.
  56.  */
  57. typedef struct _dirdesc {
  58.     int    dd_fd;
  59.     long    dd_loc;
  60.     long    dd_size;
  61.     char    dd_buf[DIRBLKSIZ];
  62. } DIR;
  63. #ifndef NULL
  64. #define NULL 0
  65. #endif
  66. extern    DIR *opendir();
  67. extern    struct direct *readdir();
  68. extern    long telldir();
  69. extern    void seekdir();
  70. #define rewinddir(dirp)    seekdir((dirp), (long)0)
  71. extern    void closedir();
  72. #endif
  73.  
  74. #ifdef KERNEL
  75. /*
  76.  * Template for manipulating directories.
  77.  * Should use struct direct's, but the name field
  78.  * is MAXNAMLEN - 1, and this just won't do.
  79.  */
  80. struct dirtemplate {
  81.     u_long    dot_ino;
  82.     short    dot_reclen;
  83.     short    dot_namlen;
  84.     char    dot_name[4];        /* must be multiple of 4 */
  85.     u_long    dotdot_ino;
  86.     short    dotdot_reclen;
  87.     short    dotdot_namlen;
  88.     char    dotdot_name[4];        /* ditto */
  89. };
  90. #endif
  91.